<?php

class Comment {
	private $id;
	private $user;
	private $text;
	private $publication;
	private $createdate;
	
	function __construct($id,$user, $text, $publication, $createdate){
		$this -> id = $id;
		$this -> user = $user;
		$this -> text = $text;
		$this -> publication = $publication;
		$this -> createdate = $createdate;
	}
	
	function getListComments($db,$id){
		$result=$db->query("SELECT * FROM comment WHERE com_id_publication = $id",2);
		$comment=new Comment($result[0]['com_IDcomment'],
						$result[0]['com_date'], 
						$result[0]['com_id_publication'],
						$result[0]['com_text'],
						$result[0]['com_id_user']);
				
		return $comment;
	
	}
	
	function getComment($db,$id){
		$result=$db->query("SELECT * FROM comment WHERE com_IDcomment = $id",2);
		$comment=new Comment($result[0]['com_IDcomment'],
						$result[0]['com_date'], 
						$result[0]['com_id_publication'],
						$result[0]['com_text'],
						$result[0]['com_id_user']);
				
		return $comment;
	
	}
	
	function insertComment($db,$comment){
		$user 			= $comment -> getUser();
		$text			= $comment -> getText();
		$publication 	= $comment -> getPublication();
		$result=$db->insert("INSERT INTO comment (com_id_user,com_id_publication,com_date,com_text)
										 VALUES($user,$publication,now(),'$text')");
		return $result;
	}	
	
	function deleteComment($db,$comment){
		$id 			= $comment -> getID();
		$result=$db->delete("DELETE FROM comment WHERE com_IDcomment = " . $id);
		return $result;
	}	
	
	function updateComment($db,$comment){
		$id 			= $comment -> getID();
		$text 			= $comment -> getText();
		$result=$db->update("UPDATE comment SET com_text='$text' WHERE com_IDcomment = " . $id);
		return $result;
	}		
	
	
	
	function getUser(){
		return $this -> user;
	}	
	
	function  setUser($user){
		$this -> user = $user;
	}	
	
	function getText(){
		return $this -> text;
	}	
	
	function  setText($text){
		$this -> text = $text;
	}	
	
	function getPublication(){
		return $this -> publication;
	}
	
	function  setPublication($publication){
		$this -> publication = $publication;
	}	
	
	function getID(){
		return $this -> id;
	}
	
	function  setID($id){
		$this -> id = $id;
	}
	
	function getDate(){
		return $this -> createdate;
	}
	
	function  setDate($createdate){
		$this -> createdate = $createdate;
	}
}

?>